/**
 * Created by zhangqingxi on 2017-04-06.
 */
var modelPath = ROOT_PATH + '/emergency/vehicle/';




//初始化负责人
function initUser() {
    $("#chargePersonName").textbox({
        editable:false,
        iconWidth: 22,
        icons: [{
            iconCls: 'icon-add',
            handler: function (e) {
                add_userInfo_func();
            }
        }, {
            iconCls: 'icon-remove',
            handler: function (e) {
                $(e.data.target).textbox('clear');
                $('#chargePersonId').val('');

            }
        }]
    });
}
function add_userInfo_func() {
    WindowManager.openLayer({
        type: 2,
        title: '选择人员信息',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
        callBack: function (data) {//窗口关闭后的回调函数
            var id = data[0].id;
            var name = data[0].realName;

            $('#chargePersonId').val(id);
            $('#chargePersonName').textbox('setValue', name);

        }
    });

}
//初始化部门
function initDept() {

    $('#deptId').combotree({
        url: findDept,
        required:true,
        editable:false,
        prompt:'请选择'
    });
}
//初始化应急队伍
function initEmergencyTeam(id) {

    $('#emergencyTeamId').combogrid({
        required: true,
        editable: false,
        readonly: false,
        panelWidth: 900,
        prompt: '请选择',
        idField: 'id',
        textField: 'name',
        queryParams: {
            sort: 'd.addTime',
            order: 'desc'
        },
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        sortOrder: true,
        striped: true,
        url: findTeam,
        columns: [[
            {field:'name', title: '队伍名称', width: 10},
            {field:'systemName',title:'建制',width:10},
            {field:'baseName',title:'基地',width:10},
            {field:'typeName',title:'队伍类型',width:10},
            {field:'majorName',title:'专业特色',width:10}
        ]]
    });
}
//初始化车辆大类
function initBigType() {

    $('#bigTypeId').combobox({
        url: dictionaryByCode + vehicleBigType,
        prompt: '请选择',
        required: true,
        editable: false,
        valueField: 'id',
        textField: 'text',
        onChange:function (newValue,oldValue) {
            $('#smallTypeId').combobox({
                value:''
            });
            findSmallTypeById(newValue);
        }
    });
}
/**
 * 根据Id查询code
 * @param id
 */
function findSmallTypeById(id) {
    $.ajax({
        type: "POST",
        url: dictionaryById+id,
        dataType: "json",
        success: function(data){
            initSmallType(data.code)
        }
    });
}
//初始化车辆小类
function initSmallType(code) {

    $('#smallTypeId').combobox({
        url:dictionaryByDatas,
        queryParams:{
            data1:code
        },
        prompt: '请选择',
        required: true,
        editable: false,
        valueField: 'id',
        textField: 'text'
    });
}
function bigTypeLoadSuccess() {
    var $val= $('#bigTypeId').val();
    findSmallTypeById($val);
    initBigType();
}